package com.huixuebao.api.controller.merchant;

import com.huixuebao.api.dto.MechanismDTO;
import com.huixuebao.api.entity.MerchantBasicsEntity;
import com.huixuebao.api.service.rpc.MerchantBasicsService;
import com.huixuebao.api.service.MechanismService;
import com.huixuebao.common.bean.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 * @author ft_yu
 * @version 1.0
 * @date 2020-11-16 22:04
 */
@Slf4j
@RestController()
@RequestMapping("/merchant")
public class MerchantController {

    @Autowired
    MechanismService mechanismService;

    @Autowired
    MerchantBasicsService merchantBasicsService;

    /**
     * @author ft_yu
     * 获取机构坐标的经纬度（x、y）轴,将没有机构地址返回前端
     * @param
     * @return
     */
    @GetMapping("/getMerchantWithoutAxis")
    public ApiResult<List<MechanismDTO>> getMerchantWithoutAxis() {
        return mechanismService.getMerchantWithoutAxis();
    }


    /**
     * @author ft_yu
     * 前端将百度请求好的经纬度保存到数据库中
     * @param
     * @return
     */
    @PostMapping("/setMerchantAxis")
    public ApiResult setMerchantAxis(MechanismDTO mechanismDTO) {
        return mechanismService.setMerchantAxis(mechanismDTO);
    }


    /**
    * @Description:将sql server中获取到的机构信息选择性插入mysql中
    * @Author: Mr.Gao
    * @Date: 2020-11-18 15:49
    */
    //@Scheduled(cron = "0 0 22 * * ?") //每天22点执行一次
    //@Scheduled(cron = "0 */1 * * * ?") //每分钟执行一次
    @PostMapping("/setMerchanismFromS")
    public ApiResult setMerchanismFromS() {
        List<MerchantBasicsEntity> mbeList = merchantBasicsService.getListByStatus();
        return mechanismService.setMerchanismFromS(mbeList);
    }

}